package com.sezi.blog.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * 博客回复
 * @author yuanyi
 * @Date 2015-4-16
 * @version 1.0
 */
@Entity
@Table(name="b_reply")
public class Reply {

	/**id*/
	private Long id;
	/**所属博文*/
	private Blog blog;
	/**所属用户*/
	private User fromUser;
	/**内容*/
	private byte[] content;
	/**上层回复（最顶级为对博文的回复）*/
	private Reply parent;
	/**子回复*/
	private List<Reply> children;
	/**创建时间*/
	private Date createTime;
	/**此层序列*/
	private Integer sort;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@ManyToOne(fetch=FetchType.EAGER,optional=false)
	public Blog getBlog() {
		return blog;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

	@ManyToOne(fetch=FetchType.EAGER,optional=false)
	public User getFromUser() {
		return fromUser;
	}

	public void setFromUser(User fromUser) {
		this.fromUser = fromUser;
	}

	@Lob
	public byte[] getContent() {
		return content;
	}

	public void setContent(byte[] content) {
		this.content = content;
	}

	@ManyToOne(fetch=FetchType.EAGER,optional=false)
	public Reply getParent() {
		return parent;
	}

	public void setParent(Reply parent) {
		this.parent = parent;
	}
	
	@OneToMany(mappedBy="parent")
	public List<Reply> getChildren() {
		return children;
	}

	public void setChildren(List<Reply> children) {
		this.children = children;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}
	
}
